package com.michael.comm.biz.resp;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class ObjectRestResp<T> extends BaseResp implements Serializable
{
    T data;

    public ObjectRestResp data(T data)
    {
        this.setData(data);
        return this;
    }

    public T getData()
    {
        return data;
    }

    public void setData(T data)
    {
        this.data = data;
    }

    public static ObjectRestResp ok(Object data)
    {
        return new ObjectRestResp<Object>().data(data);
    }

    public static ObjectRestResp ok()
    {
        return new ObjectRestResp<Object>();
    }

    public static ObjectRestResp fail(String message) {
        ObjectRestResp<Object> objectObjectRestResponse = new ObjectRestResp<>();
        objectObjectRestResponse.setMessage(message);
        objectObjectRestResponse.setStatus(400);
        return objectObjectRestResponse;
    }

    public static ObjectRestResp fail(int status, String message) {
        ObjectRestResp<Object> objectObjectRestResponse = new ObjectRestResp<>();
        objectObjectRestResponse.setMessage(message);
        objectObjectRestResponse.setStatus(status);
        return objectObjectRestResponse;
    }

    public static ObjectRestResp fail(int status, String message, Object data) {
        ObjectRestResp<Object> objectObjectRestResponse = new ObjectRestResp<>();
        objectObjectRestResponse.setData(data);
        objectObjectRestResponse.setStatus(status);
        objectObjectRestResponse.setMessage(message);
        return objectObjectRestResponse;
    }
}
